#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"


# 当前分支的名称
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

# 合并分支的名称
MERGE_BRANCH_NAME="${GIT_REFLOG_ACTION//merge /}"

echo "------$MERGE_BRANCH_NAME"

# 禁止合并的公共分支
forbidden_branches=("develop")

# 判断当前合并的分支是否属于禁止合并的分支
if [[ " ${forbidden_branches[*]} " = *" $MERGE_BRANCH_NAME "* ]]; then
 echo "检测到非法合并: $CURRENT_BRANCH_NAME merge $MERGE_BRANCH_NAME"
 echo "撤销合并中..."
 git reset --merge HEAD@{1} # 撤回合并
 echo "已撤销合并"
 exit 1
fi


